//防抖
// eslint-disable-next-line @typescript-eslint/ban-types
export function ToDebounce(fn: Function, timeout: number) {
	let id = 0;
	return function (...args: any[]) {
		clearTimeout(id);
		id = setTimeout(() => {
			fn(...args);
		}, timeout);
	};
}

//节流
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-unused-vars
export function ToThrottle(fn: Function, timeout: number, ...args: any[]) {
	let excute = true; // 是否可以执行函数
	return function (...args: any[]) {
		if (excute) {
			fn(...args);
			excute = false;
			setTimeout(() => {
				excute = true;
			}, timeout);
		}
	};
}

//获取系统信息

export function getDeviceInfo() {
	const systemInfo = uni.getSystemInfoSync();
	return {
		platform: systemInfo.platform,
		screenWidth: systemInfo.screenWidth,
		screenHeight: systemInfo.screenHeight,
		windowWidth: systemInfo.windowWidth,
		windowHeight: systemInfo.windowHeight,
		statusBarHeight: systemInfo.statusBarHeight,
		safeArea: systemInfo.safeArea,
		safeAreaInsets: systemInfo.safeAreaInsets,
	};
}
